package com.github.ylt.protocol.http;

import com.github.ylt.protocol.http.handler.HttpHandler;
import com.github.ylt.protocol.http.server.ServerImpl;

import java.util.Map;

public class HttpContextImpl extends HttpContext{

    private final String path;
    private final String protocol;
    private final ServerImpl server;
    private HttpHandler handler;

    public HttpContextImpl(String path,String protocol,ServerImpl server,HttpHandler handler){
        this.path = path;
        this.protocol = protocol;
        this.server = server;
        this.handler = handler;
    }


    @Override
    public HttpHandler getHandler() {
        return this.handler;
    }

    @Override
    public void setHandler(HttpHandler handler) {
        if(this.handler != null){
            throw new IllegalArgumentException("已经存在handler，请勿重复设置");
        }
        if(handler == null){
            throw new IllegalArgumentException("handler不能为空");
        }
        this.handler = handler;
    }

    @Override
    public String getPath() {
        return this.path;
    }

    @Override
    public ServerImpl getServer() {
        return server;
    }

    @Override
    public Map<String, Object> getAttributes() {
        return Map.of();
    }

    public String getProtocol(){
        return protocol;
    }
}
